package com.rtp2p.rtcoresdkdemo.add.ble

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import com.rtp2p.rtcoresdkdemo.add.AddViewModel
import com.rtp2p.rtcoresdkdemo.base.BaseFragment
import com.rtp2p.rtcoresdkdemo.databinding.AddBindingBleFragmentBinding

class AddBindingBleFragment : BaseFragment() {
    private val addViewModel: AddViewModel by viewModels({ requireActivity() })
    private val viewModel: AddBindingBleViewModel by viewModels()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel.init(requireContext(), addViewModel.wifiSsid, addViewModel.wifiPwd) { requireActivity().finish() }
    }

    override fun initWorkspaceAction(inflater: LayoutInflater, container: ViewGroup?): View {
        val binding = AddBindingBleFragmentBinding.inflate(layoutInflater)
        binding.lifecycleOwner = viewLifecycleOwner
        binding.vm = viewModel
        binding.btnReturn.setOnClickListener { finish() }
        return binding.root
    }

    override fun onStart() {
        super.onStart()
        viewModel.onStart()
    }

    override fun onStop() {
        super.onStop()
        viewModel.onStop()
    }
}